package cn.yitun.chat.yitunserverimapicore.business.recent.action;

import cn.yitun.chat.yituncommonmessage.result.ResultMessage;
import cn.yitun.chat.yitungeneral.annotation.action.ActionMapping;
import cn.yitun.chat.yitungeneral.annotation.parameter.JsonDefine;
import cn.yitun.chat.yitunnetsession.session.SocketSession;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.dataentity.dto.userchat.LastChatDto;
import cn.yitun.chat.yitunservercommonlib.dataentity.vo.userchat.LastChatVo;
import cn.yitun.chat.yitunservercommonlib.util.R;
import cn.yitun.chat.yitunserverimapicore.business.recent.service.RecentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;


/**
 * 最近聊天
 * @author yitun
 * @since 1.1
 */
@Component
@ActionMapping(ActionTypeConstant.RECENT_ACTION_PUSH)
public class RecentAction {

    @Resource
    private RecentService recentService;

    /**
     * 最近聊天记录 记数
     * @param socketSession
     * @return
     */
    @ActionMapping("1.1.0001")
    public Object queryCount(SocketSession socketSession, @JsonDefine("data") LastChatDto query ) {
        query.setUserId(socketSession.getKey());
        return new ResultMessage(R.param("count", recentService.lastChatCount(query)));
    }

    /**
     * 最近聊天记录 列表
     * @param socketSession
     * @return
     */
    @ActionMapping("1.1.0002")
    public Object queryList(SocketSession socketSession, @JsonDefine("data") LastChatDto query) {
        query.setUserId(socketSession.getKey());
        PageHelper.startPage(query.getCurrentPageNo(), query.getPageSize());
        List<LastChatVo> list = recentService.lastChatList(query);
        return new ResultMessage(R.param("page", new PageInfo<>(list)));
    }
    /**
     * 获取详情
     * @param socketSession
     * @return
     */
    @ActionMapping("1.1.0003")
    public Object getById(SocketSession socketSession, @JsonDefine("data") LastChatDto query) {
        return new ResultMessage(R.param("info", recentService.getById(query.getId())));
    }
    /**
     * 删除
     * @param socketSession
     * @return
     */
    @ActionMapping("1.1.0004")
    public Object remove(SocketSession socketSession, @JsonDefine("data") LastChatDto query) {
        recentService.remove(query);
        return new ResultMessage();
    }


}




